import Vue from 'vue'
import Router from 'vue-router'
const login = resolve => require(['../view/login/login.vue'], resolve)
const index = resolve => require(['../components/index.vue'], resolve)
//const home = resolve => require(['../view/index/home.vue'], resolve)
const hotline = resolve => require(['../view/hotline/hotline.vue'], resolve)//该页面热线管理
const notice = resolve => require(['../view/notice/notice.vue'], resolve) // 通知公告
const information = resolve => require(['../view/information/information.vue'], resolve)//情报公告
const monthly = resolve => require(['../view/monthly/monthly.vue'], resolve) //热线月报
const cause = resolve => require(['../view/cause/cause.vue'], resolve) //案件选登
const comment = resolve => require(['../view/comment/comment.vue'], resolve) //评论管理
const slideshow = resolve => require(['../view/slideshow/slideshow.vue'], resolve) //轮播图管理
const intro = resolve => require(['../view/overview/intro.vue'], resolve) // 12345概况，平台简介
const responsibilities = resolve => require(['../view/overview/responsibilities.vue'], resolve) // 机构职责
const workprocess = resolve => require(['../view/overview/workprocess.vue'], resolve) // 工作流程
const acceptscope = resolve => require(['../view/overview/acceptscope.vue'], resolve) // 受理范围
const acceptway = resolve => require(['../view/overview/acceptway.vue'], resolve) // 受理方式
const systemMaintenance = resolve => require(['../view/systemMaintenance/systemMaintenance.vue'], resolve) // 系统维护

const originalPush = Router.prototype.push;
Router.prototype.push = function push(location) {
    return originalPush.call(this, location).catch(err => err);
}

Vue.use(Router)



export default new Router({
    routes: [
        {
            path: '/',
            redirect: '/user/login'
        },
        {
            path: '/user/login',

            component: login
        },
        {
            //首页
            path: '/index',
            component: index,
            redirect: '/index/hotline',
            children: [
                //{ path: '/index/', component: home }, //首页
                { path: '/index/hotline', component: hotline }, //热线管理
                { path: '/index/notice', name: 'notice', component: notice }, //通知公告
                { path: '/index/information', component: information }, // 情报公告
                { path: '/index/monthly', component: monthly }, // 热线月报
                { path: '/index/cause', component: cause }, // 案件选登
                { path: '/index/slideshow', name: 'slideshow', component: slideshow }, //上传内容
                { path: '/index/comment', name: 'comment', component: comment }, // 评论管理
                { path: '/index/overview/intro', component: intro }, //12345概况，平台简介
                { path: '/index/overview/responsibilities', component: responsibilities }, //机构职责
                { path: '/index/overview/workprocess', component: workprocess }, // 工作流程
                { path: '/index/overview/acceptscope', component: acceptscope }, // 受理范围
                { path: '/index/overview/acceptway', component: acceptway }, // 受理方式
                { path: '/index/systemMaintenance', component: systemMaintenance }, // 系统维护



            ]
        },
    ]
})

// router.beforeEach((to, from, next) => {
//     // 并不是每个页面的访问都需要先登陆 

//     if (to.path.includes('login')) { // 
//         // 如果用户登陆过，则进行路由的跳转，否则重定向到登陆页
//         next()
//     } else { // 如果不是访问需要授权的页面，如新闻页，那么不需要判断是否登陆
//         let token = JSON.parse(sessionStorage.getItem('usrObj')).token
//         if (token) { // 如果有token说明你登陆过了
//             next()
//         } else {
//             // 如果是访问需要授权的页面且没有登陆过，则重定向到登陆页
//             next({ name: 'login' })
//         }
//     }
// })




